home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASCSRC.ZIP / AMORT3.PAS < prev    next >
Pascal/Delphi Source File  |  1988-01-15  |  2KB  |  70 lines

  1. program Amortization_Table;
  2.  
  3. var Month : 1..12;
  4.     Starting_Month : 1..12;
  5.     Balance : real;
  6.     Payment : real;
  7.     Interest_Rate : real;
  8.     Annual_Accum_Interest : real;
  9.     Year : integer;
  10.  
  11. procedure Initialize_Data; (* ******************** initialize data *)
  12. begin
  13.    Balance := 2500.0;
  14.    Starting_Month := 5;
  15.    Payment := 100.0;
  16.    Interest_Rate := 0.13/12.0;
  17.    Annual_Accum_Interest := 0.0; (* This is to accumulate Interest *)
  18.    Year := 1985;
  19. end;
  20.  
  21. procedure Print_Annual_Header; (* ************ print annual header *)
  22. begin
  23.    Writeln;
  24.    Writeln('Month    payment  interest    princ   balance');
  25.    Writeln;
  26. end;
  27.  
  28. procedure Calculate_And_Print; (* ************ calculate and print *)
  29. var Interest_Payment : real;
  30.     Principal_Payment : real;
  31. begin
  32.    if Balance > 0.0 then begin
  33.       Interest_Payment := Interest_Rate * Balance;
  34.       Principal_Payment := Payment - Interest_Payment;
  35.       if Principal_Payment > Balance then begin  (* loan payed off *)
  36.          Principal_Payment := Balance;             (* this month *)
  37.          Payment := Principal_Payment + Interest_Payment;
  38.          Balance := 0.0;
  39.       end
  40.       else begin  (* regular monthly payment *)
  41.          Balance := Balance - Principal_Payment;
  42.       end;
  43.       Annual_Accum_Interest := Annual_Accum_Interest+Interest_Payment;
  44.       Writeln(Month:5,Payment:10:2,Interest_Payment:10:2,
  45.               Principal_Payment:10:2,Balance:10:2);
  46.    end; (* of if Balance > 0.0 then *)
  47. end;
  48.  
  49. procedure Print_Annual_Summary; (* ********** print annual summary *)
  50. begin
  51.    Writeln;
  52.    Writeln('Total interest for ',Year:5,' = ',
  53.             Annual_Accum_Interest:10:2);
  54.    Annual_Accum_Interest := 0.0;
  55.    Year := Year + 1;
  56.    Writeln;
  57. end;
  58.  
  59. begin   (* ******************************************* main program *)
  60.    Initialize_Data;
  61.    repeat
  62.       Print_Annual_Header;
  63.       for Month := Starting_Month to 12 do begin
  64.          Calculate_And_Print;
  65.       end;
  66.       Print_Annual_Summary;
  67.       Starting_Month := 1;
  68.    until Balance <= 0.0;
  69. end.  (* of main program *)
  70.